package com.mzj.saas.jobs.bill.repository;


import com.mzj.saas.jobs.bill.entity.Cohabit;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface CohabitRepository extends PagingAndSortingRepository<Cohabit,String>, JpaSpecificationExecutor<Cohabit> {
    List<Cohabit> findByApplyId(Long applyId);

    List<Cohabit> findByApplyIdIn(List<Long> applyIds);

    int deleteByIdIn(List<String> ids);

    List<Cohabit> findByIdIn(List<String> ids);

    int deleteByApplyId(Long applyId);

    List<Cohabit> findByApplyIdAndCardNumber(Long applyId,String cardNumber);

    List<Cohabit> findByIdInOrderByApplyTimeAsc(List<String> ids);

    List<Cohabit> findByApplyIdAndStatusOrderByApplyTimeDesc(Long applyId,Integer status);

    List<Cohabit> findByApplyIdAndStatusOrderByApplyTimeAsc(Long applyId,Integer status);

    @Modifying
    @Query(value = "UPDATE `saas_house_eligible_apply_cohabit` SET status = ?2 WHERE id in (?1)", nativeQuery = true)
    int updateStatusByIdIn(List<String> ids, Integer status);

    @Modifying
    @Query(value = "UPDATE `saas_house_eligible_apply_cohabit` SET status = ?2,apply_id = ?3 WHERE id in (?1)", nativeQuery = true)
    int updateStatusAndApplyIdByIdIn(List<String> ids, Integer status,Long applyId);

    @Modifying
    @Query(value = "UPDATE `saas_house_eligible_apply_cohabit` SET status = ?3 WHERE apply_id = ?1 and status = ?2", nativeQuery = true)
    int updateStatusByApplyIdAndStatus(Long applyId, Integer status , Integer stat);

}

